GBML manual / Stacks

stack_clear

Removes every item from target, leaving it empty (stack_length(target) becomes 0, stack_empty(target) becomes true). target's own declared capacity is unchanged - it can be filled again afterward.

Syntax

stack_clear(target)

Arguments

NameType
targetstack

Returns

Nothing.

Description

Removes every item from target, leaving it empty (stack_length(target) becomes 0, stack_empty(target) becomes true). target's own declared capacity is unchanged, so it can be filled again afterward.

Useful for a fresh start - clearing an undo history when the player starts a new level, say, rather than popping items one at a time.

Example

/// @type {stack<int>}
var history = [1, 2, 3];
stack_clear(history);
var depth = stack_length(history); // 0
A real capture - the stack and its length before clearing, 3 items deepA real capture - the stack and its length before clearing, 3 items deep
A real capture - the stack and its length before clearing, 3 items deep
The same stack after stack_clear(history) - empty, and stack_length back to 0The same stack after stack_clear(history) - empty, and stack_length back to 0
The same stack after stackclear(history) - empty, and stacklength back to 0

On the GBA

The vector's clear() - O(n) in how many items target held (each one's destructor runs), identical to list_clear.

See also: stack_pushstack_popstack_lengthstack_emptyData containers